﻿using HotelCardClient.Helpers;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace HotelCardClient.ViewModels
{
    class HomeViewModel : BaseViewModel
    {
        #region Properties
        private string _name;
        public string Name 
        {
            get { return _name; }
            set { _name = value; RaisePropertyChanged("Name"); }
        }
        private string _lastname;
        public string LastName
        {
            get { return _lastname; }
            set { _lastname = value; RaisePropertyChanged("LastName"); }
        }

        private string _company;
        public string Company
        {
            get { return _company; }
            set { _company = value; RaisePropertyChanged("Company"); }
        }

        private string _credit;
        public string Credit
        {
            get { return _credit; }
            set { _credit = value; RaisePropertyChanged("Credit"); }
        }

        public DateTime? CheckInDate { get; set; }
        public DateTime? CheckOutDate { get; set; }

        #endregion


        public ICommand GetProfileCommand { get { return new DelegateCommand(OnGetProfileCommand); } }

        private void OnGetProfileCommand()
        {
            /* http://apidev.accuweather.com/locations/v1/search?q=bkk&apikey=meSocYcloNe */

            // Set a request to server side to get it.
            var url = @"http://apidev.accuweather.com";
            var client = new RestClient(url);
            var request = new RestRequest("locations/v1/search", Method.GET);
            request.AddParameter("q", "bkk");
            request.AddParameter("apikey", "meSocYcloNe");

            // easily add HTTP Headers
            //request.AddHeader("header", "value");

            // easy async support
            client.ExecuteAsync<List<RootObject>>(request, response =>
            {
                if (response.Data != null)
                {
                    var content = response.Data.First().EnglishName;
                    Name = content;
                }
            });

        }

        public ICommand CheckInCommand { get { return new DelegateCommand(OnCheckInCommand); } }
        private void OnCheckInCommand()
        {
            var dt = CheckInDate;
        }

        public ICommand CheckOutCommand { get { return new DelegateCommand(OnCheckOutCommand); } }
        private void OnCheckOutCommand()
        {
            var dt = CheckOutDate;
        }

        #region Serialize
        public class Region
        {
            public string ID { get; set; }
            public string LocalizedName { get; set; }
            public string EnglishName { get; set; }
        }

        public class Country
        {
            public string ID { get; set; }
            public string LocalizedName { get; set; }
            public string EnglishName { get; set; }
        }

        public class AdministrativeArea
        {
            public string ID { get; set; }
            public string LocalizedName { get; set; }
            public string EnglishName { get; set; }
            public int Level { get; set; }
            public string LocalizedType { get; set; }
            public string EnglishType { get; set; }
            public string CountryID { get; set; }
        }

        public class TimeZone
        {
            public string Code { get; set; }
            public string Name { get; set; }
            public double GmtOffset { get; set; }
            public bool IsDaylightSaving { get; set; }
            public object NextOffsetChange { get; set; }
        }

        public class Metric
        {
            public double Value { get; set; }
            public string Unit { get; set; }
            public int UnitType { get; set; }
        }

        public class Imperial
        {
            public double Value { get; set; }
            public string Unit { get; set; }
            public int UnitType { get; set; }
        }

        public class Elevation
        {
            public Metric Metric { get; set; }
            public Imperial Imperial { get; set; }
        }

        public class GeoPosition
        {
            public double Latitude { get; set; }
            public double Longitude { get; set; }
            public Elevation Elevation { get; set; }
        }

        public class RootObject
        {
            public int Version { get; set; }
            public string Key { get; set; }
            public string Type { get; set; }
            public int Rank { get; set; }
            public string LocalizedName { get; set; }
            public string EnglishName { get; set; }
            public string PrimaryPostalCode { get; set; }
            public Region Region { get; set; }
            public Country Country { get; set; }
            public AdministrativeArea AdministrativeArea { get; set; }
            public TimeZone TimeZone { get; set; }
            public GeoPosition GeoPosition { get; set; }
            public bool IsAlias { get; set; }
            public List<object> SupplementalAdminAreas { get; set; }
        }

#endregion
    }
}
